<!DOCTYPE html>
<html lang="en">
  <head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">


  <title>阳明的博客-blog.qikqiak.com|Kubernetes|Docker|Python|Golang|Cloud Native</title>
  <meta name="keywords" content="Kubernetes,k8s,Docker,Python,Django,Golang,Hugo,Cloud Native,微服务"/>
  <meta name="description" content="关注容器、kubernetes、devops、python、django、golang、微服务等技术。">
  <meta property="og:title" content="阳明的博客" />
  <meta name="twitter:title" content="阳明的博客" />

  <meta name="author" content=""/>
  <link href='https://blog.qikqiak.com/img/favicon.ico' rel='icon' type='image/x-icon'/>
  <meta property="og:image" content="https://blog.qikqiak.com/img/avatar.jpeg" />
  <meta name="twitter:image" content="https://blog.qikqiak.com/img/avatar.jpeg" />
  <meta name="twitter:card" content="summary" />
  <meta property="og:url" content="https://blog.qikqiak.com/" />
  <meta property="og:type" content="website" />
  <meta property="og:site_name" content="阳明的博客" />

  <meta name="generator" content="Hugo 0.34" />
  <link rel="canonical" href="https://blog.qikqiak.com/" />
  <link rel="alternate" href="https://blog.qikqiak.com/index.xml" type="application/rss+xml" title="阳明的博客">
  <link href="https://cdn.bootcss.com/KaTeX/0.7.1/katex.min.css" rel="stylesheet">
  <link href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
  <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
  <link rel="stylesheet" href="https://blog.qikqiak.com/css/main.css?t=1235" />
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic" />
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" />
  <link rel="stylesheet" href="https://blog.qikqiak.com/css/pygment_highlights.css" />
  <link rel="stylesheet" href="https://blog.qikqiak.com/css/highlight.min.css" />
  <link rel="stylesheet" href="https://blog.qikqiak.com/css/prism.css?t=123" />
  <link rel="stylesheet" href="https://blog.qikqiak.com/css/search.css" />
<meta name="keywords" content="">
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?970de9920f6089c287a7fd366138d4e9";
  var s = document.getElementsByTagName("script")[0];
  s.parentNode.insertBefore(hm, s);
})();
</script>



<link href="https://cdn.bootcss.com/photoswipe/4.1.1/photoswipe.min.css" rel="stylesheet">
<link href="https://cdn.bootcss.com/photoswipe/4.1.1/default-skin/default-skin.min.css" rel="stylesheet">



<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

<div class="pswp__bg"></div>

<div class="pswp__scroll-wrap">
    
    <div class="pswp__container">
      <div class="pswp__item"></div>
      <div class="pswp__item"></div>
      <div class="pswp__item"></div>
    </div>
    
    <div class="pswp__ui pswp__ui--hidden">
    <div class="pswp__top-bar">
      
      <div class="pswp__counter"></div>
      <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
      <button class="pswp__button pswp__button--share" title="Share"></button>
      <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>
      <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>
      
      
      <div class="pswp__preloader">
        <div class="pswp__preloader__icn">
          <div class="pswp__preloader__cut">
            <div class="pswp__preloader__donut"></div>
          </div>
        </div>
      </div>
    </div>
    <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
      <div class="pswp__share-tooltip"></div>
    </div>
    <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
    </button>
    <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
    </button>
    <div class="pswp__caption">
      <div class="pswp__caption__center"></div>
    </div>
    </div>
    </div>
</div>

<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-69668147-3', 'auto');
ga('send', 'pageview');
</script>
<script async src='//www.google-analytics.com/analytics.js'></script>

</head>

  <body>
    <nav class="navbar navbar-default navbar-fixed-top navbar-custom">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#main-navbar">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="https://blog.qikqiak.com/">阳明的博客</a>
    </div>

    <div class="collapse navbar-collapse" id="main-navbar">
      <ul class="nav navbar-nav navbar-right">
        
          
            <li>
              <a title="Home" href="https://ydzs.io">Home</a>
            </li>
          
        
          
            <li class="navlinks-container">
              <a class="navlinks-parent" href="javascript:void(0)">Categories</a>
              <div class="navlinks-children">
                
                  <a href="https://blog.qikqiak.com/page/archive/">Archive</a>
                
                  <a href="https://blog.qikqiak.com/tags">tags</a>
                
                  <a href="https://blog.qikqiak.com/tags/kubernetes">kubernetes</a>
                
                  <a href="https://blog.qikqiak.com/tags/python">python</a>
                
                  <a href="https://blog.qikqiak.com/tags/django">django</a>
                
                  <a href="https://blog.qikqiak.com/tags/ops">devops</a>
                
              </div>
            </li>
          
        
          
            <li class="navlinks-container">
              <a class="navlinks-parent" href="javascript:void(0)">海马学院</a>
              <div class="navlinks-children">
                
                  <a href="https://www.haimaxy.com/course/6y02wp/?utm_source=blog&amp;utm_campaign=referral&amp;utm_medium=topmenu">Python微服务实战</a>
                
                  <a href="https://www.haimaxy.com/course/pww13p/?utm_source=blog&amp;utm_campaign=referral&amp;utm_medium=topmenu">Webpack3.x 入门</a>
                
                  <a href="https://www.haimaxy.com/course/pjrqxm/?utm_source=blog&amp;utm_campaign=referral&amp;utm_medium=topmenu">Kubernetes 集群搭建</a>
                
              </div>
            </li>
          
        
          
            <li>
              <a title="About" href="https://blog.qikqiak.com/page/about/">About</a>
            </li>
          
        

        

        

        
          <li>
            <a href="#modalSearch" data-toggle="modal" data-target="#modalSearch" style="outline: none;">
              <span class="hidden-sm hidden-md hidden-lg">Search</span> <span id="searchGlyph" class="glyphicon glyphicon-search"></span>
            </a>
          </li>
          

      </ul>
    </div>

    <div class="avatar-container">
      <div class="avatar-img-border">
        
          <a title="阳明的博客" href="https://blog.qikqiak.com/">
            <img class="avatar-img" src="https://blog.qikqiak.com/img/avatar.jpeg" alt="阳明的博客" />
          </a>
        
      </div>
    </div>

  </div>
</nav>





  <div id="modalSearch" class="modal fade" role="dialog">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Search blog.qikqiak.com</h4>
        </div>
        <div class="modal-body">
            
<div class="aa-input-container" id="aa-input-container">
    <input type="search" id="aa-search-input" class="aa-input-search" placeholder="Search for titles or URIs..." name="search" autocomplete="off" />
    <svg class="aa-input-icon" viewBox="654 -372 1664 1664">
        <path d="M1806,332c0-123.3-43.8-228.8-131.5-316.5C1586.8-72.2,1481.3-116,1358-116s-228.8,43.8-316.5,131.5  C953.8,103.2,910,208.7,910,332s43.8,228.8,131.5,316.5C1129.2,736.2,1234.7,780,1358,780s228.8-43.8,316.5-131.5  C1762.2,560.8,1806,455.3,1806,332z M2318,1164c0,34.7-12.7,64.7-38,90s-55.3,38-90,38c-36,0-66-12.7-90-38l-343-342  c-119.3,82.7-252.3,124-399,124c-95.3,0-186.5-18.5-273.5-55.5s-162-87-225-150s-113-138-150-225S654,427.3,654,332  s18.5-186.5,55.5-273.5s87-162,150-225s138-113,225-150S1262.7-372,1358-372s186.5,18.5,273.5,55.5s162,87,225,150s113,138,150,225  S2062,236.7,2062,332c0,146.7-41.3,279.7-124,399l343,343C2305.7,1098.7,2318,1128.7,2318,1164z" />
    </svg>
</div>
<script src="https://res.cloudinary.com/jimmysong/raw/upload/rootsongjc-hugo/algoliasearch.min.js"></script>
<script src="https://res.cloudinary.com/jimmysong/raw/upload/rootsongjc-hugo/autocomplete.min.js"></script>

<script>
var client = algoliasearch("1JDRAS0AZR", "8804ac109158bb3bb60d74ce98fa332f");
var index = client.initIndex('prod_blog');

autocomplete('#aa-search-input',
{ hint: false}, {
    source: autocomplete.sources.hits(index, {hitsPerPage: 5}),
    
    displayKey: 'name',
    
    templates: {
        
        suggestion: function(suggestion) {
            return '<span>' + '<a href="https://blog.qikqiak.com/post/' + suggestion.slug + '">' +
            suggestion._highlightResult.title.value + '</a></span>';
        }
    }
});
</script>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">close</button>
        </div>
      </div>
    </div>
  </div>

    
  
  
  




  
    <div id="header-big-imgs" data-num-img=1 data-img-src-1="https://blog.qikqiak.com/img/golang-k8s.png" ></div>
  

  <header class="header-section has-img">
    
      <div class="intro-header big-img">
        
        <div class="container">
          <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
              <div class="page-heading">
                <h1>阳明的博客</h1>
                  
                    
                      <hr class="small">
                      <span class="page-subheading">关注容器、kubernetes、devops、python、golang等~~~</span>
                    
                  
                  
              </div>
            </div>
          </div>
        </div>
        <span class="img-desc" style="display: inline;"></span>
      </div>
    
    <div class="intro-header no-img">
      
      <div class="container">
        <div class="row">
          <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
            <div class="page-heading">
              <h1>阳明的博客</h1>
                
                  
                    <hr class="small">
                    <span class="page-subheading">关注容器、kubernetes、devops、python、golang等~~~</span>
                  
                
                
            </div>
          </div>
        </div>
      </div>
    </div>
  </header>


    
  <div role="main" class="container">
    <div class="row">
      <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
        

        <div class="posts-list">
          
          
            <article class="post-preview">
              <a href="https://blog.qikqiak.com/post/make-https-blog/">
                <h2 class="post-title">给博客加上HTTPS</h2>
                
              </a>

              <span class="post-meta">
  Posted on November 6, 2017
  
</span>


              <div class="post-entry">
                
                  <p>谁都不愿意在使用网站服务的时候，被恶心的运营商劫持加上一些他们的服务(真的很贱，不是吗？)，不过这能难道我们程序员吗？当然不能，上<code>https</code>，老子全站<code>https</code>，你再劫持给我看看。</p>

<p><code>https</code>证书服务大部分都是收费的，而且很贵，阿里云可以申请一个免费的证书，只能绑定一个域名，这里我们使用更加友好的免费<code>https</code>服务：<a href="https://letsencrypt.org/">Let’s Encrypt</a></p>

<p></p>
                  <a href="https://blog.qikqiak.com/post/make-https-blog/" class="post-read-more">[Read More]</a>
                
              </div>

              
                <span class="post-meta">
                
                  #<a href="https://blog.qikqiak.com/tags/https/">https</a>&nbsp;
                
                  #<a href="https://blog.qikqiak.com/tags/nginx/">nginx</a>&nbsp;
                
                  #<a href="https://blog.qikqiak.com/tags/ops/">ops</a>&nbsp;
                
                </span>
              
            </article>
          
            <article class="post-preview">
              <a href="https://blog.qikqiak.com/post/django-staticroot-staticfilesdirs-function/">
                <h2 class="post-title">Django 中STATIC_ROOT 与STATICFILES_DIRS的区别</h2>
                
              </a>

              <span class="post-meta">
  Posted on November 1, 2017
  
</span>


              <div class="post-entry">
                
                  <p>在做<code>Django</code>项目的时候，经常会遇到静态文件访问的问题，在本地开发的时候可以正常的访问静态文件，部署到服务器上后就出现各种幺蛾子了，我猜你一定也遇到过吧？之前在<code>settings.py</code>配置文件中对<code>STATIC_ROOT</code>与<code>STATICFILES_DIRS</code>两个配置项不是特别理解，总感觉都差不多，在线上就把<code>STATIC_ROOT</code>替换成<code>STATICFILES_DIRS</code>了，虽然可以解决问题，但是却没有知其所以然。</p>

<p></p>
                  <a href="https://blog.qikqiak.com/post/django-staticroot-staticfilesdirs-function/" class="post-read-more">[Read More]</a>
                
              </div>

              
                <span class="post-meta">
                
                  #<a href="https://blog.qikqiak.com/tags/python/">python</a>&nbsp;
                
                  #<a href="https://blog.qikqiak.com/tags/django/">django</a>&nbsp;
                
                </span>
              
            </article>
          
            <article class="post-preview">
              <a href="https://blog.qikqiak.com/post/python-convert-pdf-images/">
                <h2 class="post-title">利用Python 优雅的将PDF 转换成图片</h2>
                
              </a>

              <span class="post-meta">
  Posted on October 30, 2017
  
</span>


              <div class="post-entry">
                
                  <p>之前收集了很多优秀的<code>PDF</code>文档，但是需要看的时候不是很方便，需要去找到这个文件，如果是在手机上的话往往还需要下载<code>PDF</code>相关的插件才行，而且最大的问题是不便于资料的整理和分享。如果能够将<code>PDF</code>转换成网页，岂不是就能解决这些问题了？还能直接分享出去。</p>

<p>这里利用<code>PyPDF</code>包来处理<code>PDF</code>文件，为了方便快捷，我这里直接将一个页面转换成图片，就不需要去识别页面中的每一个<code>PDF</code>元素了，这是没必要的。</p>

<p></p>
                  <a href="https://blog.qikqiak.com/post/python-convert-pdf-images/" class="post-read-more">[Read More]</a>
                
              </div>

              
                <span class="post-meta">
                
                  #<a href="https://blog.qikqiak.com/tags/python/">python</a>&nbsp;
                
                  #<a href="https://blog.qikqiak.com/tags/pdf/">PDF</a>&nbsp;
                
                </span>
              
            </article>
          
            <article class="post-preview">
              <a href="https://blog.qikqiak.com/post/what-is-service-mesh/">
                <h2 class="post-title">服务网格(Service Mesh)是什么?</h2>
                
              </a>

              <span class="post-meta">
  Posted on October 21, 2017
  
</span>


              <div class="post-entry">
                
                  <p>现在最火的后端架构无疑是<code>微服务</code>了，微服务将之前的单体应用拆分成了许多独立的服务应用，每个微服务都是独立的，好处自然很多，但是随着应用的越来越大，微服务暴露出来的问题也就随之而来了，微服务越来越多，管理越来越麻烦，特别是要你部署一套新环境的时候，你就能体会到这种痛苦了，随之而来的<strong>服务发现、负载均衡、Trace跟踪、流量管理、安全认证</strong>等等问题。如果从头到尾完成过一套微服务框架的话，你就会知道这里面涉及到的东西真的非常多。当然随着微服务的不断发展，微服务的生态也不断完善，最近就发现新一代的微服务开发就悄然兴起了，那就是<code>服务网格/Service Mesh</code>。</p>

<p></p>
                  <a href="https://blog.qikqiak.com/post/what-is-service-mesh/" class="post-read-more">[Read More]</a>
                
              </div>

              
                <span class="post-meta">
                
                  #<a href="https://blog.qikqiak.com/tags/microservice/">microservice</a>&nbsp;
                
                  #<a href="https://blog.qikqiak.com/tags/service-mesh/">Service Mesh</a>&nbsp;
                
                  #<a href="https://blog.qikqiak.com/tags/%E6%9C%8D%E5%8A%A1%E7%BD%91%E6%A0%BC/">服务网格</a>&nbsp;
                
                  #<a href="https://blog.qikqiak.com/tags/%E5%BE%AE%E6%9C%8D%E5%8A%A1/">微服务</a>&nbsp;
                
                </span>
              
            </article>
          
            <article class="post-preview">
              <a href="https://blog.qikqiak.com/post/kubernetes-rollout-update/">
                <h2 class="post-title">Kubernetes Deployment滚动升级</h2>
                
              </a>

              <span class="post-meta">
  Posted on October 18, 2017
  
</span>


              <div class="post-entry">
                
                  <p>我们<code>k8s</code>集群使用的是1.7.7版本的，该版本中官方已经推荐使用<code>Deployment</code>代替<code>Replication Controller</code>(rc)了，<code>Deployment</code>继承了rc的全部功能外，还可以查看升级详细进度和状态，当升级出现问题的时候，可以使用回滚操作回滚到指定的版本，每一次对Deployment的操作，都会保存下来，变能方便的进行回滚操作了，另外对于每一次升级都可以随时暂停和启动，拥有多种升级方案：<code>Recreate</code>删除现在的<code>Pod</code>，重新创建；<code>RollingUpdate</code>滚动升级，逐步替换现有<code>Pod</code>，对于生产环境的服务升级，显然这是一种最好的方式。</p>

<p></p>
                  <a href="https://blog.qikqiak.com/post/kubernetes-rollout-update/" class="post-read-more">[Read More]</a>
                
              </div>

              
                <span class="post-meta">
                
                  #<a href="https://blog.qikqiak.com/tags/kubernetes/">kubernetes</a>&nbsp;
                
                  #<a href="https://blog.qikqiak.com/tags/deployment/">deployment</a>&nbsp;
                
                </span>
              
            </article>
          
            <article class="post-preview">
              <a href="https://blog.qikqiak.com/post/kubernetes-monitor-prometheus-grafana/">
                <h2 class="post-title">Kubernetes使用Prometheus搭建监控平台</h2>
                
              </a>

              <span class="post-meta">
  Posted on October 17, 2017
  
</span>


              <div class="post-entry">
                
                  <p>最近在测试环境搭建了<code>Kubernetes</code>集群环境，迁移了部分测试环境的应用，由于测试集群性能不是很好，有时会遇到集群资源不够的情况，一般情况下我们是直接通过Dashboard的资源统计图标进行观察的，但是很显然如果要上到生产环境，就需要更自动化的方式来对集群、Pod甚至容器进行监控了。<code>Kubernetes</code>内置了一套监控方案：influxdb+grafana+heapster。但由于之前我们的应用的业务监控使用的是<code>Prometheus</code>，所以这里准备使用<code>Prometheus</code>来完成k8s的集群监控。</p>
                  <a href="https://blog.qikqiak.com/post/kubernetes-monitor-prometheus-grafana/" class="post-read-more">[Read More]</a>
                
              </div>

              
                <span class="post-meta">
                
                  #<a href="https://blog.qikqiak.com/tags/kubernetes/">kubernetes</a>&nbsp;
                
                  #<a href="https://blog.qikqiak.com/tags/prometheus/">prometheus</a>&nbsp;
                
                  #<a href="https://blog.qikqiak.com/tags/grafana/">grafana</a>&nbsp;
                
                  #<a href="https://blog.qikqiak.com/tags/influxdb/">influxdb</a>&nbsp;
                
                </span>
              
            </article>
          
            <article class="post-preview">
              <a href="https://blog.qikqiak.com/post/django-decorator-usage/">
                <h2 class="post-title">Python装饰器简介</h2>
                
              </a>

              <span class="post-meta">
  Posted on November 14, 2016
  
</span>


              <div class="post-entry">
                
                  <p>装饰器本质上是一个<code>Python</code>函数，它可以让其他函数在不需要做任何代码变动的前提下增加额外功能，装饰器的返回值也是一个函数对象。它经常用于有切面需求的场景，比如：插入日志、性能测试、事务处理、缓存、权限校验等场景。装饰器是解决这类问题的绝佳设计，有了装饰器，我们就可以抽离出大量与函数功能本身无关的雷同代码并继续重用。概括的讲，<strong>装饰器的作用就是为已经存在的对象添加额外的功能</strong>。</p>

<p></p>
                  <a href="https://blog.qikqiak.com/post/django-decorator-usage/" class="post-read-more">[Read More]</a>
                
              </div>

              
                <span class="post-meta">
                
                  #<a href="https://blog.qikqiak.com/tags/python/">python</a>&nbsp;
                
                  #<a href="https://blog.qikqiak.com/tags/%E8%A3%85%E9%A5%B0%E5%99%A8/">装饰器</a>&nbsp;
                
                </span>
              
            </article>
          
            <article class="post-preview">
              <a href="https://blog.qikqiak.com/post/awk-base-compute/">
                <h2 class="post-title">用awk做基本运算</h2>
                
              </a>

              <span class="post-meta">
  Posted on March 31, 2016
  
</span>


              <div class="post-entry">
                
                  <p><code>awk</code>是非常强大的文本处理工具，之前经常见到脚本里面有使用，但是没有自己完完整整来写过awk命令。正好今天公司里有一个非常的大的日志文件需要分析。需求是将日志文件中记录的耗时时间评价值、最大值、最小值计算出来。日志的格式如下：</p>

<pre><code class="language-shell">[2016-03-30 00:02:02,475] [17243] [140344433927936] [MainThread] [tasks.py:733] DEBUG [upload to oss] upload file /data/image5/user_upload_image/20160330/00/1458483897397580_101183475_1459267295740.jpg to oss cost time 28 ms
</code></pre>

<p></p>
                  <a href="https://blog.qikqiak.com/post/awk-base-compute/" class="post-read-more">[Read More]</a>
                
              </div>

              
                <span class="post-meta">
                
                  #<a href="https://blog.qikqiak.com/tags/ops/">ops</a>&nbsp;
                
                  #<a href="https://blog.qikqiak.com/tags/linux/">linux</a>&nbsp;
                
                  #<a href="https://blog.qikqiak.com/tags/awk/">awk</a>&nbsp;
                
                </span>
              
            </article>
          
            <article class="post-preview">
              <a href="https://blog.qikqiak.com/post/nginx-301-redirect/">
                <h2 class="post-title">Nginx中如何设置301跳转</h2>
                
              </a>

              <span class="post-meta">
  Posted on February 27, 2016
  
</span>


              <div class="post-entry">
                
                  <p>网站中带<code>www</code>和不带都可以访问，但是这样却会不利于网站<code>SEO</code>的，会分权，所以需要将二者的访问合并到一起，这特别在网站架设之初就应该好好规划。</p>

<p>有很多的第三方DNS解析服务，提供了直接的显示跳转的服务，比如<code>dnspod</code>，但是最近我在使用的过程中发现该服务非常的不稳定，导致网站经常性的访问不了。所以就打算自己来做，方法很简单，就是<code>301跳转</code>，<strong>301是永久跳转</strong>，<strong>302是临时性跳转</strong>。</p>

<p></p>
                  <a href="https://blog.qikqiak.com/post/nginx-301-redirect/" class="post-read-more">[Read More]</a>
                
              </div>

              
                <span class="post-meta">
                
                  #<a href="https://blog.qikqiak.com/tags/ops/">ops</a>&nbsp;
                
                  #<a href="https://blog.qikqiak.com/tags/nginx/">nginx</a>&nbsp;
                
                  #<a href="https://blog.qikqiak.com/tags/301/">301</a>&nbsp;
                
                </span>
              
            </article>
          
            <article class="post-preview">
              <a href="https://blog.qikqiak.com/post/python-process-csv-file/">
                <h2 class="post-title">用python处理csv文件</h2>
                
              </a>

              <span class="post-meta">
  Posted on May 5, 2015
  
</span>


              <div class="post-entry">
                
                  <p><code>CSV</code>通常是纯文本文件。可以用<code>Sublime Text</code>或者<code>EXCEL</code>打开，<code>python</code>提供了一个非常强大的处理csv文件的库csv。</p>

<p>一般情况，如果csv文件不是很复杂则可以直接输出文件中每行的数据，代码如下：</p>

<pre><code class="language-python">import csv

def read_csv_file(path):
    with open(path, 'rb') as f:  # r表示读取，b表示读取的文件
        reader = csv.reader(f)
        for row in reader:
            print row
    f.close()
</code></pre>

<p></p>
                  <a href="https://blog.qikqiak.com/post/python-process-csv-file/" class="post-read-more">[Read More]</a>
                
              </div>

              
                <span class="post-meta">
                
                  #<a href="https://blog.qikqiak.com/tags/python/">python</a>&nbsp;
                
                  #<a href="https://blog.qikqiak.com/tags/csv/">csv</a>&nbsp;
                
                </span>
              
            </article>
          
        </div>

        
          <ul class="pager main-pager">
            
              <li class="previous">
                <a href="https://blog.qikqiak.com/page/3">&larr; Newer Posts</a>
              </li>
            
            
              <li class="next">
                <a href="https://blog.qikqiak.com/page/5">Older Posts &rarr;</a>
              </li>
            
          </ul>
        
      </div>
    </div>
  </div>

    <footer>
  <div class="container">
    <div class="row">
      <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
        <ul class="list-inline text-center footer-links">
          
              <li>
                <a href="mailto:icnych@gmail.com" title="Email me">
                  <span class="fa-stack fa-lg">
                    <i class="fa fa-circle fa-stack-2x"></i>
                    <i class="fa fa-envelope fa-stack-1x fa-inverse"></i>
                  </span>
                </a>
              </li>
          
              <li>
                <a href="https://github.com/cnych" title="GitHub">
                  <span class="fa-stack fa-lg">
                    <i class="fa fa-circle fa-stack-2x"></i>
                    <i class="fa fa-github fa-stack-1x fa-inverse"></i>
                  </span>
                </a>
              </li>
          
              <li>
                <a href="https://weibo.com/cnych" title="微博">
                  <span class="fa-stack fa-lg">
                    <i class="fa fa-circle fa-stack-2x"></i>
                    <i class="fa fa-weibo fa-stack-1x fa-inverse"></i>
                  </span>
                </a>
              </li>
          
              <li>
                <a href="https://instagram.com/cnych" title="Instagram">
                  <span class="fa-stack fa-lg">
                    <i class="fa fa-circle fa-stack-2x"></i>
                    <i class="fa fa-instagram fa-stack-1x fa-inverse"></i>
                  </span>
                </a>
              </li>
          
          
          <li>
            <a href="https://blog.qikqiak.com/index.xml" title="RSS">
              <span class="fa-stack fa-lg">
                <i class="fa fa-circle fa-stack-2x"></i>
                <i class="fa fa-rss fa-stack-1x fa-inverse"></i>
              </span>
            </a>
          </li>
          
        </ul>
        <p class="credits copyright text-muted">
          

          &nbsp;&bull;&nbsp;
          2018

          
            &nbsp;&bull;&nbsp;
            <a href="https://blog.qikqiak.com/">阳明的博客</a>
          
        </p>
        
        <p class="credits theme-by text-muted">
          <a href="http://gohugo.io">Hugo v0.34</a> powered &nbsp;&bull;&nbsp; Theme by <a href="http://deanattali.com/beautiful-jekyll/">Beautiful Jekyll</a> adapted to <a href="https://github.com/halogenica/beautifulhugo">Beautiful Hugo</a>
          
        </p>
      </div>
    </div>
  </div>
</footer>

<script src="https://cdn.bootcss.com/KaTeX/0.7.1/katex.min.js"></script>
<script src="https://cdn.bootcss.com/KaTeX/0.7.1/contrib/auto-render.min.js"></script>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://blog.qikqiak.com/js/main.min.js"></script>
<script src="https://blog.qikqiak.com/js/highlight.min.js"></script>
<script> hljs.initHighlightingOnLoad(); </script>
<script> renderMathInElement(document.body); </script>
<script src="https://blog.qikqiak.com/js/prism.js?t=123"></script>
<script src="https://cdn.bootcss.com/photoswipe/4.1.1/photoswipe.min.js"></script>
<script src="https://cdn.bootcss.com/photoswipe/4.1.1/photoswipe-ui-default.min.js"></script>
<script src="https://blog.qikqiak.com/js/load-photoswipe.min.js"></script>



<script async src="https://www.googletagmanager.com/gtag/js?id=UA-69668147-3"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'UA-69668147-3');
</script>

  </body>
</html>

